// import blogsTable from '../db/blogsMock.js'
import { Blogs } from '../model/Blogs.js'



let fn_list = async (ctx) => {
    let blogs = Blogs.findAll();
    ctx.render('blogs.html', {
        blogs
    })
}


let fn_getById = async (ctx) => {
    let id = ctx.params.id || 0;
    let blog = await Blogs.findByPk(id);
    ctx.render('blogsAddOrEdit.html', { blog })
}


let fn_add = async (ctx) => {
    let obj = ctx.request.body;
    Blogs.create(obj);
    ctx.body = '新增成功'
}


let fn_update = async (ctx) => {
    ctx.body = '修改博客'
}


let fn_del = async (ctx) => {
    ctx.body = '删除博客'
}

export const obj = {
    'get /blogs': fn_list,
    'get /blogs/:id': fn_getById,
    'post /blogs': fn_add,
    'put /blogs/:id': fn_update,
    'delete /blogs/:id': fn_del
}


